/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * 
 * Project Name:lmrp-base
 * Create Time: 2016年3月9日 上午8:55:16
 */
package com.lenovo.lmrp.base.event;

import java.io.Serializable;

import com.lenovo.sdc.framework.util.JSONHelper;
import com.lenovo.sdc.framework.util.exception.ErrorCode;
import com.lenovo.sdc.framework.util.exception.TraceableException;

/**
 * Wrap event
 * @author wujin
 * @version v1.0
 */
public class EventContent <T> implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private EventSource source;
    private EventCode code;
    private T content;

    public EventSource getSource() {
        return source;
    }

    public void setSource(EventSource source) {
        this.source = source;
    }

    public EventCode getCode() {
        return code;
    }

    public void setCode(EventCode code) {
        this.code = code;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }
    
    public String toJson() {
        try {
            return JSONHelper.toJSON(this);
        }
        catch (Exception exp) {
            TraceableException.writeLog(ErrorCode.COMM_PARSE_FAILED, "", exp);
            return "{\"source\":\""+ source.name() + "\",code\":\"" + code.getCode() + "\"content\":null}";
        }
    }
}
